package com.billing.web.controller.archives;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Iterator;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import com.billing.model.entity.TUserEducation;
import com.billing.model.entity.TUserWorkexperience;
import com.billing.service.impl.UserWorkexperienceServiceImpl;

@RequestMapping(value="/userWork")
@Controller
public class UserWorkexperienceController {

	@Resource
	private UserWorkexperienceServiceImpl userWorkexperienceService;
	
	SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
	
	@RequestMapping(value ="/savework",method = RequestMethod.POST)
	@ResponseBody
	public String savework(HttpServletRequest request,HttpServletResponse response) throws IOException{
		int userid=(Integer) request.getSession().getAttribute("userid");
		String img="";
		String start_time=request.getParameter("starttime");
		String end_time=request.getParameter("endtime");
		String unitname=request.getParameter("unitname");
		String positions=request.getParameter("positions");
		String salaryStr=request.getParameter("salary");
		Double salary=Double.valueOf(salaryStr);
		String witness=request.getParameter("witness");
		String mobile=request.getParameter("mobile");
	    TUserWorkexperience userWorkexperience=new TUserWorkexperience();
	    Long endtime;
	    Long starttime;
		try {
			endtime = format.parse(end_time).getTime();
			starttime = format.parse(start_time).getTime();
			userWorkexperience.setStarttime(starttime);
			userWorkexperience.setEndtime(endtime);
		} catch (ParseException e) {
		}
		userWorkexperience.setMobile(mobile);
		userWorkexperience.setPositions(positions);
		userWorkexperience.setSalary(salary);
		userWorkexperience.setUnitname(unitname);
		userWorkexperience.setUserId(userid);
		userWorkexperience.setWitness(witness);
		int fal=userWorkexperienceService.insertTUserWorkexperience(userWorkexperience);
		if(fal>0){
			img="保存成功";
		}else{
			img="保存失败了";
		}
	    return img;
	}
}
